/**
 * 包名：com.pactera.config.security
 * 文件名：AjaxAccessDeniedHandler.java
 * 版本信息：1.0.0
 * 日期：2019年1月8日-下午3:51:46
 * Copyright (c) 2019 Pactera 版权所有
 */
 
package com.pactera.config.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;

/**
 * 无权限访问
 */
@Component
public class ApiAccessDeniedHandler implements AccessDeniedHandler {
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        
    	logger.info("###### Access Denied!");
        
        String respJson = JSON.toJSONString(AuthResultVO.result(AuthResultEnum.ACCESS_DEFINED,false));
        
        logger.info("###### Access Resp:{}", respJson);
        
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(respJson);
    }
}
